/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-11-06     SummerGift   first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

#include <stdlib.h>
#include <string.h>

#include "App_XSpider.h"
#include "Module_Steering.h"


// 	Steer Param Test-Part------------------------------------------	

//MODULE_STEERING module_steering = {
//	.Property_SteerType = SG90,
//	.Property_PwmDevName = "pwm2",
//	.Property_PWM_CHANNEL = 1,
//	.Property_PulseMINus = 500,
//	.Property_PulseMAXus = 2200,
//	.Property_AngleMAX = 180,
//	.Property_InitAngle = 90 
//};

//void SteerPulse(int argc,char **argv)
//{
//    
//    rt_uint32_t num = atoi(argv[1]); 
//    module_steering.Method_SetPulse(&module_steering,num*1000);
//    
//}
//MSH_CMD_EXPORT(SteerPulse , SteerPulseUs <pulse>(500-2500)us);

//void SteerAngle(int argc,char **argv)
//{
//    
//    rt_uint16_t Angle = atoi(argv[1]); 
//    module_steering.Method_SetAngle(&module_steering,Angle);
//    
//}
//MSH_CMD_EXPORT(SteerAngle , SteerAngle <Angle>(0-MAX));

APP_XSPIDER app_XSpider;

void XSpider_eye(int argc,char **argv)
{
    if(strcmp(argv[1],"red") == 0){
		app_XSpider.Method_EyeChange(&app_XSpider,RED);	
	}else if(strcmp(argv[1],"green") == 0){
		app_XSpider.Method_EyeChange(&app_XSpider,GREEN);	
	}else if(strcmp(argv[1],"blue") == 0){
		app_XSpider.Method_EyeChange(&app_XSpider,BLUE);	
	}else if(strcmp(argv[1],"off") == 0){
		app_XSpider.Method_EyeChange(&app_XSpider,NONE);
	}else{
		rt_kprintf("Warning: Wrong Color\n");
	}
    
}
MSH_CMD_EXPORT(XSpider_eye , XSpider_eye <color>(off/red/green/blue));

void XSpider_joint(int argc,char **argv)
{
    if(strcmp(argv[1],"L1_D1") == 0){
		app_XSpider.dev_Steering[L1_D1].Method_SetAngle(&(app_XSpider.dev_Steering[L1_D1]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L1_D2") == 0){
		app_XSpider.dev_Steering[L1_D2].Method_SetAngle(&(app_XSpider.dev_Steering[L1_D2]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L1_D3") == 0){
		app_XSpider.dev_Steering[L1_D3].Method_SetAngle(&(app_XSpider.dev_Steering[L1_D3]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L2_D1") == 0){
		app_XSpider.dev_Steering[L2_D1].Method_SetAngle(&(app_XSpider.dev_Steering[L2_D1]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L2_D2") == 0){
		app_XSpider.dev_Steering[L2_D2].Method_SetAngle(&(app_XSpider.dev_Steering[L2_D2]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L2_D3") == 0){
		app_XSpider.dev_Steering[L2_D3].Method_SetAngle(&(app_XSpider.dev_Steering[L2_D3]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L3_D1") == 0){
		app_XSpider.dev_Steering[L3_D1].Method_SetAngle(&(app_XSpider.dev_Steering[L3_D1]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L3_D2") == 0){
		app_XSpider.dev_Steering[L3_D2].Method_SetAngle(&(app_XSpider.dev_Steering[L3_D2]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L3_D3") == 0){
		app_XSpider.dev_Steering[L3_D3].Method_SetAngle(&(app_XSpider.dev_Steering[L3_D3]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L4_D1") == 0){
		app_XSpider.dev_Steering[L4_D1].Method_SetAngle(&(app_XSpider.dev_Steering[L4_D1]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L4_D2") == 0){
		app_XSpider.dev_Steering[L4_D2].Method_SetAngle(&(app_XSpider.dev_Steering[L4_D2]),atoi(argv[2]));
	}else if(strcmp(argv[1],"L4_D3") == 0){
		app_XSpider.dev_Steering[L4_D3].Method_SetAngle(&(app_XSpider.dev_Steering[L4_D3]),atoi(argv[2]));
	}else{
		rt_kprintf("Warning: Wrong param input\n");
	}
    
}
MSH_CMD_EXPORT(XSpider_joint , XSpider_joint <label> <angle>);

int main(void)
{
	APP_XSpider_Config(&app_XSpider);
	app_XSpider.Method_Run(&app_XSpider);

// 	Steer Param Test-Part------------------------------------------	
 
//	Module_Steering_Config(&module_steering);
//	module_steering.Method_Enable(&module_steering);
	
    return 0;
}


